package microcredit.gui.base;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.jdesktop.swingx.combobox.ListComboBoxModel;

public class EnumComboBoxModel extends ListComboBoxModel<Object> {

	private final Object nullValue;
	
	public EnumComboBoxModel(Object[] values, Object nullValue) {
		super(createList(values, nullValue));
		this.nullValue = nullValue;
	}
	
	public Object getNullValue() {
		return nullValue;
	}
	
	private static List<Object> createList(Object[] values, Object nullValue) {
		List<Object> list = new ArrayList<Object>();
		if (nullValue != null) {
			list.add(nullValue);
		}
		list.addAll(Arrays.asList(values));
		return list;
	}

}
